{include file='public/head'}
<body>
{load href="__LIB__/formSelects/formSelects-v4.css" /}
<style type="text/css" media="screen">
header {
    color: black;
}
</style>
<div class="x-body" >
	<form id="form" class="layui-form">
		<input type="hidden" name="id" value="{$data.id}">

		  <div class="layui-form-item">
		    <label class="layui-form-label">权限名称</label>
		    <div class="layui-input-block">
		    <input type="text" id="role_name"  name="role_name" lay-verify="requirede" autocomplete="off" placeholder="请输入权限名称" class="layui-input" value="{$data.role_name}">
		    </div>
		  </div>

		<div class="layui-form-item">
			<label class="layui-form-label">功能项</label>
			<div class="layui-input-block">
				<select name="rules" lay-verify="required" xm-select-search="" xm-select="select1">
					<option value=""></option>
					{volist name="auth" id="vo"}
					<option value="{$vo.id}" {if condition="in_array($vo.id,explode(',',$data.rules))"}selected{/if}>{$vo.name}</option>
					{/volist}
				</select>
			</div>
		</div>

		<div class="layui-form-item">
		    <div class="layui-input-block">
				<button  class="layui-btn" lay-filter="add" lay-submit="">修改</button>
		    </div>
		</div>


	</form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
	//全局定义一次, 加载formSelects
	layui.config({
		base: '/static/lib/formSelects/' //此处路径请自行处理, 可以使用绝对路径
	}).extend({
		formSelects: 'formSelects-v4'
	});

	layui.use(['form','layer','formSelects'], function(){
		$ = layui.jquery;
		var form = layui.form
				,layer = layui.layer,formSelects = layui.formSelects;

		//自定义验证规则
		form.verify({

		});

		//监听提交
		form.on('submit(add)', function(data){
			console.log(data);
			var form = new FormData();
			var t = $('#form').serializeArray();
			$.each(t, function() {
				form.append(this.name,this.value);
			});
			$.ajax({
				url:"{:url('admin/Auth/edit')}",
				type:"post",
				data:form,
				dataType: "json",
				processData:false,
				contentType:false,
				success:function(data){
					if(data.code == 1){
						layer.msg(data.msg,{icon: 1, time: 2000});
						setTimeout(function () {
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //执行关闭
							parent.location.href = window.parent.location;//返回父级页面
						},2000)
					}else{
						layer.msg(data.msg,{icon: 2, time: 2000});
					}
				}
			});
			return false;
		});

	});

</script>
